import Vue from 'vue'
import VueRouter from 'vue-router'
import Router from 'vue-router'
import login from '../views/login'
import register from '../views/register'
import main from '../views/main'
import study_center from '../views/study_center'
import personal from '../views/personal'
import application_center from '../views/application_center'
import ammucation from '../views/ammucation'
import shop from '../views/shop.vue'
import main_starNews from '../views/main_starNews'
import search_select from '../views/search_select'
import main_parent from '../views/main_parent'
import main_garden from '../views/main_garden'
import main_teacher from '../views/main_teacher'
import studyCenter_garden from '../views/studyCenter_garden'
import shopCar from '../views/shopCar'
import application_detail from '../views/application_detail'
import application_garden from '../views/application_garden'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'login',
        component: login
    },
    {
        path: '/login',
        name: 'login',
        component: login
    },
    {
        path: '/register',
        name: 'register',
        component: register
    },
    {
        path: '/main',
        name: 'main',
        component: main,
    },
    { path: '/main_starNews', name: 'main_starNews', component: main_starNews },


    {
        path: '/study_center',
        name: 'study_center',
        component: study_center
    },
    {
        path: '/personal',
        name: 'personal',
        component: personal
    },
    {
        path: '/application_center',
        name: 'application_center',
        component: application_center
    },
    {
        path: '/ammucation',
        name: 'ammucation',
        component: ammucation
    },
    {
        path: '/shop',
        name: 'shop',
        component: shop
    },
    {
        path: '/search_select',
        name: 'search_select',
        component: search_select
    },
    {
        path: '/main_parent',
        name: 'main_parent',
        component: main_parent
    },
    {
        path: '/main_garden',
        name: 'main_garden',
        component: main_garden
    },
    {
        path: '/main_teacher',
        name: 'main_teacher',
        component: main_teacher
    },
    {
        path: '/studyCenter_garden',
        name: 'studyCenter_garden',
        component: studyCenter_garden
    },
    {
        path: '/shopCar',
        name: 'shopCar',
        component: shopCar
    },
    {
        path: '/application_detail',
        name: 'application_detail',
        component: application_detail
    },
    {
        path: '/application_garden',
        name: 'application_garden',
        component: application_garden
    },
    // application_garden


]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
Vue.use(Router)

router.beforeEach((to, from, next) => {
    const isLogin = localStorage.eleToken ? true : false;
    if (to.path == '/login' || to.path == '/register') {
        next();
    } else {
        isLogin ? next() : next('/login');
    }
})


export default router